<%@ Page Language="C#" MasterPageFile="~/MasterDefault.master" AutoEventWireup="true"
    CodeBehind="ActivitiesForm.aspx.cs" Inherits="TeamTime.ActivitiesForm" Title="Team Time - Activities Form" %>

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
    <asp:ScriptManager runat="server" ID="ScriptManager1" EnablePartialRendering="true">
    </asp:ScriptManager>
    <clib:UpdatePanelExtender runat="server" ID="UpdatePanelExtender1" UpdateMode="Conditional">
        <ContentTemplate>
            <br />
            <h3>
                Activities &nbsp; &nbsp;&nbsp;<asp:Button ID="btnAdd" runat="server" Text="Add a new record"
                    OnClick="btnAdd_Click" />
            </h3>
            <asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False" DataKeyNames="ID"
                DataSourceID="SqlDataSource1" Width="400px" OnItemInserted="DetailsView1_ItemInserted"
                OnModeChanged="DetailsView1_ModeChanged" BorderStyle="None" >
                <HeaderStyle Height="0" BorderStyle="Dotted" />
                <InsertRowStyle BorderStyle="Dotted" />
                <CommandRowStyle BorderStyle="Dotted" />
                <EditRowStyle BorderStyle="Dotted" />
                <RowStyle BorderStyle="Dotted" />
                <Fields>
                    <asp:TemplateField HeaderStyle-Height="0" HeaderStyle-BorderStyle="None" ItemStyle-BorderStyle="None">
                        <InsertItemTemplate >
                            Activity &nbsp;<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("Description") %>'
                                Width="250px"></asp:TextBox>
                        </InsertItemTemplate>
                    </asp:TemplateField>
                    <asp:CommandField ShowInsertButton="True" ItemStyle-BorderStyle="None" />
                </Fields>
            </asp:DetailsView>
              <asp:GridView ID="GridView1" runat="server" AllowPaging="False" AllowSorting="True"
                AutoGenerateColumns="False" DataKeyNames="ID" DataSourceID="SqlDataSource1" SkinID="GridView"
                OnRowCancelingEdit="GridView1_RowCancelingEdit">
                <Columns>
                    <asp:BoundField DataField="ID" HeaderText="ID" Visible="False" ReadOnly="True" SortExpression="ID" />
                    <asp:BoundField DataField="Description" HeaderText="Activity" SortExpression="Description"
                        ControlStyle-Width="400px" />
                    <asp:CommandField ShowDeleteButton="True" ShowEditButton="True" />
                    <asp:TemplateField>
                        <ItemTemplate>
                        
                            <asp:HyperLink ID="hyp1" runat="server" Text="Enterprises" NavigateUrl='<%# "CompaniesForm.aspx?searchfor=" + DataBinder.Eval(Container, "DataItem.Description") + "&searchactivities=true" %>'></asp:HyperLink>
                        </ItemTemplate>
                    </asp:TemplateField>
                </Columns>
                <EmptyDataTemplate>
                    No records found</EmptyDataTemplate>
            </asp:GridView>
            <br />
            
            <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:TEP %>"
                DeleteCommand="DELETE FROM [Activity] WHERE [ID] = @ID" 
                InsertCommand="INSERT INTO [Activity] (Description, RecordDate, UserIDModifiedBy) VALUES (@Description,getdate(),@UserIDModifiedBy)"
                SelectCommand="SELECT * FROM [Activity]" 
                UpdateCommand="UPDATE [Activity] SET Description = @Description, RecordDate=getdate(), UserIDModifiedBy=@UserIDModifiedBy WHERE [ID] = @ID">
                <DeleteParameters>
                    <asp:Parameter Name="ID" Type="Int32" />
                </DeleteParameters>
                <UpdateParameters>
                    <asp:Parameter Name="Description" Type="String" />
                    <asp:Parameter Name="ID" Type="Int32" />
                    <asp:Parameter Name="UserIDModifiedBy"  Type="Int32" />
                </UpdateParameters>
                <InsertParameters>
                    <asp:Parameter Name="Description" Type="String" />
                    <asp:Parameter Name="ID" Type="Int32" />
                    <asp:Parameter Name="UserIDModifiedBy"  Type="Int32" />
                </InsertParameters>
            </asp:SqlDataSource>
        </ContentTemplate>
    </clib:UpdatePanelExtender>

    <script type="text/javascript">
        function popup(id) {

            var url = "ActivitiesEnterprises.aspx?ID=" + id;
            //alert(url);
            var win = window.open(url, 'ent', 'menubar=0,location=0,scrollbars=1,resizable=1');
            win.focus();
        }
    </script>

</asp:Content>
